# Time-stamp: <09 May 00 10:30:02 giron1

=head1 NAME

SIDL_LAT - Package for creation of lattices -

=head1 SYNOPSIS

 use SIDL_LAT;

=head1 DESCRIPTION

Create a lattice according to the SLF format from a hash in input.
It creates a lattice for each g_section of the hash, and writes it 
down on a file.

=head1 SEE ALSO

The following packages descriptions

L<SIDL_SUBLAT>

=head1 AUTHOR

 Daniela Raddino
 $Id: SIDL_LAT.pm,v 1.1 2007/10/08 09:26:03 schweitz Exp $

=head1 LOG

 $Log: SIDL_LAT.pm,v $
 Revision 1.1  2007/10/08 09:26:03  schweitz
 version 2.4, lib vergessen

 Revision 1.1  2000/05/12 15:01:25  giron1
 First package version


=cut

package SIDL_LAT;

#----------------------------------------------------------------------
# perl packages
#----------------------------------------------------------------------

use SIDL_SUBLAT;

#----------------------------------------------------------------------

=head1 FUNCTIONS

Here is a description of the functions used:

=head2 lattice_main


=cut

#Windows version of vrecog needs some specific handling, esp. a sil word node
# instead of !ENTER and !EXIT.
$winvrecog = 1;
#main program, for each g_section it will call a routine 

sub lattice_main {
  my $filenameprefix=shift;
  local ($recgram_point)=@_;

  foreach (sort keys %$recgram_point) {
    my $lang_point=$$recgram_point{$_};
    foreach (sort keys %$lang_point) {
      local (%node_hash,@link_array);
      local ($node)=0;
      $g_section_point=$$lang_point{$_};
	    
      @array_g=@$g_section_point;
      next unless ($#array_g);

      SIDL_SUBLAT::sublat(\$node,\@array_g,\%node_hash,\@link_array);
	    
      #add the silence nodes at beginning and end
      if ($winvrecog){$node_hash{0}="sil";}
      else {$node_hash{0}="!ENTER";}
      $node++;
      if ($winvrecog){$node_hash{$node}="sil";}
      else {$node_hash{$node}="!EXIT";}

      push @link_array,[0,1];
#vrecog doesn't like that
#	    push(@link_array,[1,0]);
      push @link_array,[2,$node];
#vrecog doesn't like that
#	    push(@link_array,[$node,2]); 
      $node++;

      #write down on file
      open LAT_FILE,">$filenameprefix$_.lat";
      $debug && warn "opened $filenameprefix$_.lat\n";
      my $numnode=$node;
      my $numlink=scalar(@link_array);
      $debug && warn "numlink $numlink numnode $node\n"; 
# unfortunately, wnet_comp doesn't like comments.
#     printf LAT_FILE "#LATTICE from  Sidl Document \n#\n";
      printf LAT_FILE "N=$numnode L=$numlink\n";
#     printf LAT_FILE "#\n#Node definitions \n#\n";
      my $i;
      for ($i=0;$i<=$numnode-1;$i++) {
	my $word=$node_hash{$i};
	printf LAT_FILE "I=%-3s W=%-10s\n",$i,$word;
      }
#     printf LAT_FILE "#\n#Link definitions \n#\n";
      for ($i=0;$i<=$numlink-1;$i++) {
	printf LAT_FILE "J=%-3s S=%-3d E=%-3d\n",$i,$link_array[$i][0],$link_array[$i][1];
      }    
      close LAT_FILE;
    }
  }
}
1;
